package offer.algorithm;

/**
 * Description：
 * Author: zhangc
 * Date：2017/7/18 22:13
 */
public class AdjustArray14 {

    public static int[] adjustArray(int[] array) {

        int left = 0, right = array.length - 1, temp;
        while (true) {
            for (int i = left; i < array.length; i++) {
                if ((array[i] & 1) == 0) {
                    left = i;
                    break;
                }
            }
            for (int i = right; i >= 0; i--) {
                if ((array[i] & 1) != 0) {
                    right = i;
                    break;
                }
            }
            if (left < right && !(left == 0 && right == array.length - 1)) {
                temp = array[left];
                array[left] = array[right];
                array[right] = temp;
            } else {
                break;
            }
        }
        return array;
    }
}
